<template>
    <div class="example-page">
        <h2>圆形图片裁剪示例</h2>

        <ImageCropper :diameter="200" @cropped="handleCropped" />
    </div>
</template>

<script>
import CircleCropper from '@/components/CircleCropper.vue';
import ImageCropper from '@/components/ImageCropper.vue';

export default {
    components: {
        CircleCropper,
        ImageCropper
    },
    data() {
        return {
            croppedImage: null
        };
    },
    methods: {
        handleCropSuccess(result) {
            console.log('裁剪成功:', result);
            this.croppedImage = result;
        },
        uploadImage() {
            // 这里可以实现上传逻辑
            // 例如使用 FormData 上传 Blob
            if (this.croppedImage) {
                const formData = new FormData();
                formData.append('image', this.croppedImage.blob, 'avatar.jpg');

                // 发送到服务器
                // axios.post('/api/upload', formData)...

                console.log('准备上传图片...');
            }
        },
        handleCropped(blob) {
            // 处理裁剪结果
            const formData = new FormData();
            formData.append('avatar', blob, 'avatar.png');

            // 上传逻辑...
        }
    }
};
</script>

<style scoped>
.example-page {
    padding: 20px;
}

.upload-section {
    text-align: center;
    margin-top: 20px;
}

.upload-button {
    padding: 10px 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
}
</style>